<template>
  <div  id="building">
    <div style="width: 40%;margin-left: 30%;margin-top: 80px">
      <h3 @click="getInfo">个人信息</h3>
      <el-form :model="userVo" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="userVo.nikeName"></el-input>
        </el-form-item>
        <el-form-item label="性别">
          <el-radio-group v-model="userVo.gender">
            <el-radio label="男"></el-radio>
            <el-radio label="女"></el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="userVo.age"></el-input>
        </el-form-item>
        <el-form-item label="手机号" prop="name">
          <el-input v-model="userVo.phone"></el-input>
        </el-form-item>
        <el-form-item label="取餐地址" prop="name">
          <el-input v-model="userVo.addr"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="update()">修改</el-button>
          <el-button @click="resetForm('userVo')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

  </div>
</template>

<script>
export default {
  name: "User",
  data() {
    return {
      userVo: {
        nikeName: '',
        phone: '',
        addr: '',
        age: '',
        gender: ''
      },

    };
  },
  created() {
    this.getInfo()
  },
  methods: {
    //修改个人信息
    update(){
      if (this.userVo.gender === '男') {
        this.userVo.gender = 0
      } else {
        this.userVo.gender = 1
      }
      this.$axios({
        method: 'post',
        url: '/user/update',
        data: this.userVo
      }).then(res => {
        this.getInfo()
        alert(res.data.message)
      })
    },
    //获取个人信息
    getInfo(){
      this.$axios({
        method: 'get',
        url: '/user/info',
      }).then(res => {
        this.userVo = res.data.data.data
        if (this.userVo.gender === 0) {
          this.userVo.gender = '男'
        } else {
          this.userVo.gender = '女'
        }
      })
    },
    resetForm() {
      this.userVo = ''
    }
  }
}
</script>

<style scoped>
#building{
  background:url("https://ghxt-atlbb.oss-cn-zhangjiakou.aliyuncs.com/image/banner1653651316000.jpg") no-repeat;
  width:100%;
  height:100%;
  position:fixed;
  background-size:100% 100%;
}
</style>
